/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : battleLogic
	/// </summary>
	public class BattleUnitPOD : IPOD 
    {
        public readonly static Func<BattleUnitPOD> FACTORY = () => new BattleUnitPOD();
		public static Func<BattleUnitPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  玩家id，多个单位可能同属一个玩家
        /// </summary>
		public long pid;
		/// <summary>
        /// 
        /// </summary>
		public int configID;
		/// <summary>
        /// 
        /// </summary>
		public int skinID;
		/// <summary>
        /// 
        /// </summary>
		public int unitType;
		/// <summary>
        /// 
        /// </summary>
		public int level;
		/// <summary>
        /// 
        /// </summary>
		public int[] attrs;
		/// <summary>
        /// 
        /// </summary>
        private Dictionary<int, int> m_skills;
		/// <summary>
        /// 
        /// </summary>
        private List<int> m_initBuff;
		/// <summary>
        /// 
        /// </summary>
		public int radius;
		/// <summary>
        /// 
        /// </summary>
		public int formationIndex;
		/// <summary>
        /// 
        /// </summary>
		public int weaknessPoint;
		/// <summary>
        /// 
        /// </summary>
		public int weaknessType;
		/// <summary>
        /// 
        /// </summary>
		public string ai;
		/// <summary>
        /// 
        /// </summary>
        private List<int> m_flankAngle;
		/// <summary>
        /// 
        /// </summary>
        private List<int> m_backAngle;
		/// <summary>
        /// 
        /// </summary>
		public int pet;
		
		
        public Dictionary<int, int> skills
        {
            get
            {
                if(m_skills == null)
                {
                    m_skills = new();
                }
                return m_skills;
            }
            private set => m_skills = value;
        }
        public Dictionary<int, int> unsafe_skills
        {
        	get => m_skills;
        	set => m_skills = value;
        }
        public List<int> initBuff
        {
            get
            {
                if(m_initBuff == null)
                {
                    m_initBuff = new();
                }
                return m_initBuff;
            }
            private set => m_initBuff = value;
        }
        public List<int> unsafe_initBuff
        {
        	get => m_initBuff;
        	set => m_initBuff = value;
        }
        public List<int> flankAngle
        {
            get
            {
                if(m_flankAngle == null)
                {
                    m_flankAngle = new();
                }
                return m_flankAngle;
            }
            private set => m_flankAngle = value;
        }
        public List<int> unsafe_flankAngle
        {
        	get => m_flankAngle;
        	set => m_flankAngle = value;
        }
        public List<int> backAngle
        {
            get
            {
                if(m_backAngle == null)
                {
                    m_backAngle = new();
                }
                return m_backAngle;
            }
            private set => m_backAngle = value;
        }
        public List<int> unsafe_backAngle
        {
        	get => m_backAngle;
        	set => m_backAngle = value;
        }
		
		/*-- constructors --*/
		public BattleUnitPOD() {}
		public BattleUnitPOD(long pid, int configID, int skinID, int unitType, int level, int[] attrs, Dictionary<int, int> skills, List<int> initBuff, int radius, int formationIndex, int weaknessPoint, int weaknessType, string ai, List<int> flankAngle, List<int> backAngle, int pet) {
			this.pid = pid;
			this.configID = configID;
			this.skinID = skinID;
			this.unitType = unitType;
			this.level = level;
			this.attrs = attrs;
			this.m_skills = skills;
			this.m_initBuff = initBuff;
			this.radius = radius;
			this.formationIndex = formationIndex;
			this.weaknessPoint = weaknessPoint;
			this.weaknessType = weaknessType;
			this.ai = ai;
			this.m_flankAngle = flankAngle;
			this.m_backAngle = backAngle;
			this.pet = pet;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(pid);
            _out.Write_int(configID);
            _out.Write_int(skinID);
            _out.Write_int(unitType);
            _out.Write_int(level);
            _out.Write_intArr(attrs);
            _out.Write_map_int_int(m_skills);
            _out.Write_list_int(m_initBuff); 
            _out.Write_int(radius);
            _out.Write_int(formationIndex);
            _out.Write_int(weaknessPoint);
            _out.Write_int(weaknessType);
            _out.Write_string(ai);
            _out.Write_list_int(m_flankAngle); 
            _out.Write_list_int(m_backAngle); 
            _out.Write_int(pet);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            pid = _in.Read_long();
            if(!_in.HasRemaining()) return;
            configID = _in.Read_int();
            if(!_in.HasRemaining()) return;
            skinID = _in.Read_int();
            if(!_in.HasRemaining()) return;
            unitType = _in.Read_int();
            if(!_in.HasRemaining()) return;
            level = _in.Read_int();
            if(!_in.HasRemaining()) return;
            attrs = _in.Read_intArr();
            if(!_in.HasRemaining()) return;
            m_skills = _in.Read_map_int_int();
            if(!_in.HasRemaining()) return;
            m_initBuff = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            radius = _in.Read_int();
            if(!_in.HasRemaining()) return;
            formationIndex = _in.Read_int();
            if(!_in.HasRemaining()) return;
            weaknessPoint = _in.Read_int();
            if(!_in.HasRemaining()) return;
            weaknessType = _in.Read_int();
            if(!_in.HasRemaining()) return;
            ai = _in.Read_string();
            if(!_in.HasRemaining()) return;
            m_flankAngle = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            m_backAngle = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            pet = _in.Read_int();
        }
		
		public BattleUnitPOD Clone() {
            BattleUnitPOD o = DynamicFactory();
            o.pid = pid;
            o.configID = configID;
            o.skinID = skinID;
            o.unitType = unitType;
            o.level = level;
            if (attrs != null) {
                o.attrs = (int[])attrs.Clone();
            }
            if (m_skills != null) {
                o.m_skills = new (m_skills);
            }
            if (m_initBuff != null) {
                o.m_initBuff = new (m_initBuff);
            }
            o.radius = radius;
            o.formationIndex = formationIndex;
            o.weaknessPoint = weaknessPoint;
            o.weaknessType = weaknessType;
            o.ai = ai;
            if (m_flankAngle != null) {
                o.m_flankAngle = new (m_flankAngle);
            }
            if (m_backAngle != null) {
                o.m_backAngle = new (m_backAngle);
            }
            o.pet = pet;
            return o;
        }
        
        public void Clear() {
            pid = default;
            configID = default;
            skinID = default;
            unitType = default;
            level = default;
            attrs = default;
            m_skills = default;
            m_initBuff = default;
            radius = default;
            formationIndex = default;
            weaknessPoint = default;
            weaknessType = default;
            ai = default;
            m_flankAngle = default;
            m_backAngle = default;
            pet = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "BattleUnitPOD [";
			str += "pid=";
			str += pid;
			str += ", configID=";
			str += configID;
			str += ", skinID=";
			str += skinID;
			str += ", unitType=";
			str += unitType;
			str += ", level=";
			str += level;
			str += ", attrs=";
			str += attrs;
			str += ", skills=";
			str += m_skills.ToString<int, int>();
			str += ", initBuff=";
			str += m_initBuff.ToString<int>();
			str += ", radius=";
			str += radius;
			str += ", formationIndex=";
			str += formationIndex;
			str += ", weaknessPoint=";
			str += weaknessPoint;
			str += ", weaknessType=";
			str += weaknessType;
			str += ", ai=";
			str += ai;
			str += ", flankAngle=";
			str += m_flankAngle.ToString<int>();
			str += ", backAngle=";
			str += m_backAngle.ToString<int>();
			str += ", pet=";
			str += pet;
			str += "]";
			return str;
		}
		
	}
}